package com.herench.bs.rtconfig;

import com.herench.bs.support.DeployEvEnum;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 上传文对象类
 * @author luoxiaoming 2018/12/1
 */
public class CleverContextConfig {


    private static final String CONFIG_FILE_PATH = "bs.properties";
    private static final String TOKEN_LIFE_CYCLE = "token-life-cycle";
    private static final String DEPLOY_EV = "deploy-ev";
    private static final String AUTH_URL = "auth-url";
    private int tokenLifeCycle;
    private String deployEv;
    private String authUrl;

    public CleverContextConfig() {
        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(CONFIG_FILE_PATH);
        Properties properties = new Properties();
        try {
            properties.load(in);
            String tokenLifeCycle = properties.getProperty(TOKEN_LIFE_CYCLE);
            if (StringUtils.hasLength(tokenLifeCycle)) {
                this.tokenLifeCycle = Integer.valueOf(tokenLifeCycle);
            } else {
                this.tokenLifeCycle = 10 * 60 * 1000;
            }
            String deployEv = properties.getProperty(DEPLOY_EV);
            if (StringUtils.hasLength(deployEv)) {
                this.deployEv = deployEv;
            } else {
                this.deployEv = DeployEvEnum.publish.name();
            }
            String authUrl = properties.getProperty(AUTH_URL);
            this.authUrl = authUrl;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public int getTokenLifeCycle() {
        return tokenLifeCycle;
    }


    public String getDeployEv() {
        return deployEv;
    }

    public String getAuthUrl() {
        return authUrl;
    }
}
